package DAO;

import Models.User;
import Interfaces.IUser;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GetUser_Dao implements IUser {

    public GetUser_Dao() {

    }

    @Override
    public User SearchUser(String Username) {
        //init
        Connection conn = null;
        try {
            conn = javaconnect.ConnecrDb("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/nlr");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GetUser_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }
        User x;
        x = new User();
        if (conn != null) {
            ResultSet rs;
            rs = null;
            PreparedStatement pst;
            pst = null;

            String sql;
            sql = "select * from  user where username=? ";
            try {
                pst = conn.prepareStatement(sql);
                pst.setString(1, Username);

                rs = pst.executeQuery();
                if (rs.next()) {
                    x.setName(rs.getString("name"));
                    x.setSurname(rs.getString("surname"));
                    x.setPass(rs.getString("pass"));
                    x.setPhone(rs.getString("phone"));
                    x.setUsername(rs.getString("username"));
                    x.setEmail(rs.getString("email"));
                    x.setNOShops(rs.getString("noshop"));

                    
                }
            } catch (SQLException e) {
                return x;
            }

            return x;
        } else {
            return x;
        }
    }

}
